
Imports System.Collections
Imports System

Public Structure Person
    
    Dim Name As String
    Dim Age As Integer
    
End Structure


Public Module Main

	public Sub Main()

		dim dictionary as Hashtable
		dim p as Person

		' Create a Hastable - this is a reference type, so we use New
		' to create the object on the managed CLR heap.

		dictionary = new Hashtable()

		' Setup our Person Structure - This is value type, so we do
		' not use New, and the type is just allocated on the stack.


		p.Name = "Richard Anderson"
		p.Age = 28

		' Add our Person value type to the dictionary.  This will cause
		' the value type to be boxed within a reference type, and added
		' to the dictionary.

		dictionary.Add( "Rich", p )

		' Setup the value type (overwriting the old values)

		p.Name = "Sam Anderson"
		p.Age = 27
		
		' Add our Person value type to the dictionary.  Again, this will cause
		' the value type to be boxed within a reference type and adde to the
		' dictionary.

		dictionary.Add( "Sam", p )

		' Retreive a person by Name.  The CType keyword tells VB that
		' the object type returned by the Item function is a Person
		' type.  Since the Person type is a value type, the CLR knows
		' to unbox the Person type from the returned object type.

		p = CType( dictionary.Item("Rich"), Person )

		' We use the Person type

		Console.WriteLine("Name is {0} and Age is {1}", _
			p.Name, p.Age )
		
		
	End Sub

End Module

